import axios from 'axios';
import { Toast } from 'vant';
let mytoast = null
axios.defaults.baseURL = 'http://111.229.157.253:8848'
axios.defaults.timeout = 5000

axios.interceptors.request.use((config)=>{
  mytoast = Toast.loading({
    duration: 0,
    forbidClick: true,
    message: "加载中..."
  })
  return config
})

axios.interceptors.response.use((config)=>{
    const key = ["a","b","c","d","e","f","g","h","i"]
    const data = JSON.parse(JSON.stringify(config.data))
    const newData = data.reduce((prev,item,index)=>{
        prev[key[index]] = item.data
        return prev
    },{})
    config.data = newData
  mytoast.clear()
  return config
})

export default axios